package com.boc.langxiang.ui.dialog;

import android.app.Dialog;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.DialogFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.TextView;

import com.boc.langxiang.R;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by admin on 2016/6/29.
 */
public class ContactCustomerDialogFragment extends DialogFragment {

    @BindView(R.id.tv_me_customer_phone)
    TextView tvMeCustomerPhone;
    @BindView(R.id.tv_me_customer_weixin)
    TextView tvMeCustomerWeixin;
    @BindView(R.id.tv_me_customer_cancel)
    TextView tvMeCustomerCancel;
    @BindView(R.id.linlayout_me_contactcustomer)
    View view;
    private boolean mCancleAble;

    public interface CustomerListener {
        void phoneClick();

        void weiXinClick();

        void cancelClick();

        void emptyClick();
    }

    private CustomerListener mCustomerListener;

    public CustomerListener getCustomerListener() {
        return mCustomerListener;
    }

    public void setCustomerListener(CustomerListener customerListener) {
        this.mCustomerListener = customerListener;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View inflate = inflater.inflate(R.layout.dialog_contact_customer, container, false);
        Dialog dialog = getDialog();
        if (dialog == null) {
            return null;
        }
        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        dialog.getWindow().setBackgroundDrawable(new ColorDrawable(0));
        ButterKnife.bind(this, inflate);
        return inflate;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {

        if(mCustomerListener!=null){
            tvMeCustomerPhone.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    mCustomerListener.phoneClick();
                }
            });

            tvMeCustomerWeixin.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    mCustomerListener.weiXinClick();
                }
            });

            tvMeCustomerCancel.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    mCustomerListener.cancelClick();
                }
            });

            view.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    mCustomerListener.emptyClick();
                }
            });


        }

    }

    @NonNull
    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        Dialog dialog = super.onCreateDialog(savedInstanceState);
        dialog.getWindow().getAttributes().windowAnimations = R.style.me_pop_anim_bottom_style;
        return dialog;

    }

    /**
     * false表示
     *
     * @param cancleAble false表示back键没有反应
     */
    public void setBackCancelAble(boolean cancleAble) {
        setCancelable(cancleAble);
    }


}
